package com.sgb.goods.viewmodel;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.sgb.goods.api.GoodsCallBack;
import com.sgb.goods.api.GoodsNet;
import com.sgb.goods.entity.AddGoodsBrandEntity;
import com.sgb.goods.utils.base.viewmodel.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.SharedPreferenceUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 描述：添加品牌（询价发布、新增采购品 ）
 *
 * @author qiangHeNoo
 * <p>
 * 时间：2021.12.10
 */
public class AddGoodsBrandModel extends BaseViewModel {

    public ObservableField<AddGoodsBrandEntity> brandEntity3 = new ObservableField<>();
    public MutableLiveData<Boolean> onSuccess = new MutableLiveData<>(false);

    public void saveBrand() {
        showLoading();
        String companyId = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.REAL_ID, "");
        Objects.requireNonNull(brandEntity3.get()).setCompanyId(companyId);
        Map<String, Object> data = new HashMap<>(5);
        data.put("companyId", companyId);
        data.put("id", Objects.requireNonNull(brandEntity3.get()).getId());
        data.put("brandName", Objects.requireNonNull(brandEntity3.get()).getBrandName());
        data.put("mark", Objects.requireNonNull(brandEntity3.get()).getMark());
        data.put("cid3", Objects.requireNonNull(brandEntity3.get()).getCid3());

        GoodsNet.getInstance().getGoodsApi().saveBrand(data).enqueue(new GoodsCallBack<BaseEntity<Object>>() {
            @Override
            public void onSuccess(BaseEntity<Object> data) {
                onSuccess.postValue(true);
            }
        });
    }

}
